package Gather.StreamExercise.StreamDome001;

import java.util.ArrayList;
import java.util.Collections;
import java.util.stream.Stream;

/**
 * ClassName:StreamDome008
 * Package:Gather.StreamExercise
 * Description:
 *
 * @Author:ZhangXin
 * @Create2023/2/23-22:53
 * @Version:v1.0
 */
public class StreamDome008 {

    public static void main(String[] args) {
        /*
         * Stream<T>distinct()   元素去重,依赖(hashCode和equals方法)
         * static<T>Stream<T> concat(Stream a,Stream b)  合并a和b两个流为一个流*/

        ArrayList<String> list1 = new ArrayList<>();
        Collections.addAll(list1, "张无忌", "张无忌", "张无忌", "张无忌", "张强",
                "张三丰", "张翠山", "张良", "王二麻子", "谢广坤");

        ArrayList<String> list2 = new ArrayList<>();
        Collections.addAll(list2, "周芷若", "赵敏");

        //Stream<T>distinct()   元素去重,依赖(hashCode和equals方法)
        //底层：(hashCode和equals方法) 如果是Student对象则需要手动重写hashCode和equals方法
        list1.stream().distinct().forEach(s-> System.out.println(s));

        //static<T>Stream<T> concat(Stream a,Stream b)  合并a和b两个流为一个流
        System.out.println("==================================");
        Stream.concat(list1.stream(),list2.stream()).distinct().forEach(s-> System.out.println(s));
    }
}
